/** 
  学生学位获得时间
*/
<template>
    <div>
        <div>
            <condition-card
                @reset="reset"
                @search="onSubmit"
                label-position="right"
                label-width="150px"
            >
                <el-row :gutter="24" style="height: 50px;">
                    <el-col :span="8">
                        <el-form-item label="项目开始时间">
                            <el-date-picker
                                v-model="queryForm.condition.startTime"
                                type="date"
                                clearable
                                style="width: 100%"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                :picker-options="startDatePicker"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="项目结束时间">
                            <el-date-picker
                                v-model="queryForm.condition.endTime"
                                type="date"
                                clearable
                                style="width: 100%"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                :picker-options="endDatePicker"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="国家/地区">
                            <el-select
                                v-model.trim="queryForm.condition.nation"
                                clearable
                                filterable
                                style="width: 100%"
                                @change="getCollege"
                                placeholder
                            >
                                <el-option
                                    v-for="item in options.country"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="24" style="height: 50px;">
                    <el-col :span="8">
                        <el-form-item label="合作大学">
                            <el-select
                                v-model.trim="queryForm.condition.partnerCollege"
                                clearable
                                filterable
                                style="width: 100%"
                                placeholder
                            >
                                <el-option
                                    v-for="item in options.collegeCn"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="学号">
                            <el-input
                                style="width: 100%"
                                v-model.trim="queryForm.condition.studentId"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="姓名">
                            <el-input
                                style="width: 100%"
                                v-model.trim="queryForm.condition.studentName"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <!-- 搜索框结束 -->

                <!-- 列表页开始 -->
            </condition-card>
            <el-card shadow="never" v-loading="loading" body-style="padding: 24px;">
                <h1 class="condition-title">校际交流项目学生学位获得时间</h1>
                <div class="sub-title">
                    <div class="float-right" style="display: flex;">
                        <el-button @click="exportTime()">导出</el-button>
                    </div>
                </div>
                <edu-table
                    :pagination="false"
                    :order="true"
                    :tooltipEffect="tooltipEffect"
                    stripe
                    :data="dataList"
                    size="mini"
                    @selection-change="handleSelectionChange"
                >
                    <edu-table-column
                        label="学号"
                        prop="studentId"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="姓名"
                        prop="studentName"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="学院"
                        prop="facultyName"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="专业"
                        prop="professionName"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="项目名称"
                        prop="projectName"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="项目负责人"
                        prop="principal"
                        width="120"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="国家/地区"
                        prop="nation"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="合作大学"
                        prop="partnerCollege"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="开始时间"
                        prop="startTime"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="结束时间"
                        prop="endTime"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="获得对方学位时间"
                        prop="oppositeDegreeTime"
                        width="140"
                        align="center"
                    >
                        <template slot-scope="scope">
                            <el-date-picker
                                v-model="scope.row.oppositeDegreeTime"
                                type="date"
                                clearable
                                style="width: 100% !important"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                v-show="!scope.row.ifEdit"
                            ></el-date-picker>
                            <span v-show="scope.row.ifEdit">
                                {{ scope.row.oppositeDegreeTime }}
                            </span>
                        </template>
                    </edu-table-column>
                    <!-- 操作 -->
                    <edu-table-column :label="$t('base.operate')" fit width="120" align="left">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                v-show="!scope.row.ifEdit"
                                @click="saveTime(scope.row)"
                            >
                                保存
                            </el-button>
                            <el-button
                                type="text"
                                v-show="scope.row.ifEdit"
                                @click="editTime(scope.row)"
                            >
                                编辑
                            </el-button>
                            <el-button
                                type="text"
                                v-show="!scope.row.ifEdit"
                                @click="cancelTime(scope.row)"
                            >
                                取消
                            </el-button>
                        </template>
                    </edu-table-column>
                </edu-table>
                <el-row type="flex" class="row-bg" justify="end">
                    <el-col>
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="queryForm.pageNum_"
                            :page-sizes="[20, 40, 80, 100]"
                            :page-size="queryForm.pageSize_"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="queryForm.total_"
                            style="float:right;margin-top:10px"
                        ></el-pagination>
                    </el-col>
                </el-row>
            </el-card>
        </div>
        <edu-export-dialog :title="$t('message.prompt')" ref="downloadRef"></edu-export-dialog>
    </div>
</template>
<script>
import { queryDic } from 'common/src/api/dictionary'
import baseUrl from 'common/src/api/interSchoolExchange/env'
import UTILS from 'common/src/utils/utils'
import InterSchoolComAppApi from 'common/src/api/interSchoolExchange/InterSchoolComApp'
import statisticalApi from 'common/src/api/interSchoolExchange/statisticalAnalysis'
export default {
    data() {
        return {
            uploadUrl: `${baseUrl}/pgIntlConference/importConference`,
            startDatePicker: this.beginDate(),
            endDatePicker: this.processDate(),
            queryForm: {
                pageNum_: 1,
                pageSize_: 20,
                total_: 0,
                condition: {
                    nation: '',
                    partnerCollege: '',
                    startTime: '',
                    endTime: '',
                    studentId: '',
                    studentName: '',
                    schoolUser: false
                }
            },
            dataList: [],
            multipleSelection: {
                ids: []
            },
            options: {
                conferenceLevel: [
                    // 顶级会议
                    { value: 1, label: this.$t('conOfIntAcaCon.topMeeting') },
                    // A类会议
                    { value: 2, label: this.$t('conOfIntAcaCon.AMeeting') },
                    // B类会议
                    { value: 3, label: this.$t('conOfIntAcaCon.BMeeting') }
                ],
                collegeCn: [],
                country: []
            }
        }
    },

    created() {
        if (localStorage.getItem('sessiondata')) {
            // 获取当前用户auths权限
            if (JSON.parse(localStorage.getItem('sessiondata')).auths) {
                this.auths = JSON.parse(localStorage.getItem('sessiondata')).auths
                if (this.auths) {
                    this.auths.forEach(val => {
                        if (val.authCode === 'interSchool-tempSet-schoolUser') {
                            this.queryForm.condition.schoolUser = true
                        }
                    })
                }
            }
        }
    },
    mounted() {
        // 初始化列表页
        this.getListData()
        this.getCountry()
    },
    methods: {
        beginDate() {
            let _this = this
            return {
                disabledDate(time) {
                    if (_this.queryForm.condition.endTime) {
                        //如果结束时间不为空，则小于结束时间
                        return (
                            new Date(_this.queryForm.condition.endTime).getTime() < time.getTime()
                        )
                    } else {
                        // return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
                    }
                }
            }
        },
        processDate() {
            let _this = this
            return {
                disabledDate(time) {
                    if (_this.queryForm.condition.startTime) {
                        //如果开始时间不为空，则结束时间大于开始时间
                        return (
                            new Date(_this.queryForm.condition.startTime).getTime() >
                            time.getTime() + 24 * 60 * 60 * 1000
                        )
                    } else {
                        // return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
                    }
                }
            }
        },
        async getCountry() {
            // // 筛选条件字典查询
            // let data = {
            //     lang: this.$store.getters.language || 'cn',
            //     type: 'allChild',
            //     keys: [
            //         'G_GJQU' // 国家/地区
            //     ]
            // }
            // await queryDic(data).then(res => {
            //     UTILS.fillSelect(
            //         {
            //             country: 'G_GJQU' // 国家/地区
            //         },
            //         res.data,
            //         this.options
            //     )
            // })
            this.options.country = []

            statisticalApi.getALLCollege().then(res => {
                if (res.code === 200) {
                    res.data.list.forEach(val => {
                        this.options.country.push({
                            label: val.nameCN,
                            value: val.id
                        })
                    })
                }
            })
        },
        getCollege(val) {
            if (val) {
                let parm = {
                    collegeId: null,
                    countryId: val
                }
                this.queryForm.condition.partnerCollege = ''
                this.options.collegeCn = []
                InterSchoolComAppApi.getCollegeListByNationCode(parm).then(res => {
                    res.data.forEach(col => {
                        this.options.collegeCn.push({
                            value: col.id,
                            label: col.collegeName
                        })
                    })
                })
            } else {
                this.queryForm.condition.partnerCollege = ''
                this.options.collegeCn = []
            }
        },

        // 导出
        exportTime() {
            let parm = {
                ids: this.multipleSelection.ids,
                nation: this.queryForm.condition.nation,
                partnerCollege: this.queryForm.condition.partnerCollege,
                startTime: this.queryForm.condition.startTime,
                endTime: this.queryForm.condition.endTime,
                studentId: this.queryForm.condition.studentId,
                studentName: this.queryForm.condition.studentName,
                schoolUser:this.queryForm.condition.schoolUser
            }
            if (this.dataList.length === 0) {
                this.$message.error('无数据')
            } else {
                this.$refs.downloadRef.open()
                statisticalApi.exportDegree(parm).then(res => {
                    if (res.data) {
                        let path = `${baseUrl}/sysDictionary/downFile?path=` + res.data
                        window.open(path)
                        this.$message({
                            message: this.$t('base.exportSuccess'),
                            type: 'success'
                        })
                        this.$refs.downloadRef.close()
                    }
                })
            }
        },
        test() {},

        // 修改学生学位获得时间
        saveTime(row) {
            let parm = {
                id: row.id,
                time: row.oppositeDegreeTime?moment(row.oppositeDegreeTime).format("YYYY-MM-DD HH:mm:ss"):''
            }
            statisticalApi.saveDegree(parm).then(res => {
                if (res.code === 200) {
                    this.$message({
                        message: '保存成功',
                        type: 'success'
                    })
                    this.getListData()
                    row.ifEdit = true
                }
            })
        },
        editTime(row) {
            row.ifEdit = false
        },
        cancelTime(row) {
            this.$confirm('您确定要取消修改吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                row.ifEdit = true
                this.getListData()
            })
        },

        // 重置筛选框
        reset() {
            // this.queryForm = {
            //     pageNum_: 1,
            //     pageSize_: 20,
            //     total_: 0,
            //     condition: {
            //         nation: '',
            //         partnerCollege: '',
            //         startTime: '',
            //         endTime: '',
            //         studentId: '',
            //         studentName: ''
                    
            //     }
            // }
            this.queryForm.pageNum_ = 1,
            this.queryForm.pageSize_ = 20,
            this.queryForm.total_ = 0,
            this.queryForm.condition.nation = ''
            this.queryForm.condition.partnerCollege = ''
            this.queryForm.condition.startTime = ''
            this.queryForm.condition.endTime = ''
            this.queryForm.condition.studentId = ''
            this.queryForm.condition.studentName = ''
            this.getListData()
        },

        // 查询按钮
        onSubmit() {
            this.queryForm.pageNum_ = 1
            this.queryForm.total_ = 0
            this.queryForm.pageSize_ = 20
            this.getListData()
        },

        // 获取列表
        getListData() {
            let _this = this
            this.dataList = []
            this.multipleSelection.ids = []
            statisticalApi.listDegree(this.queryForm).then(res => {
                res.data.list.forEach(revList => {
                    revList.ifEdit = true
                    _this.dataList.push(revList)
                    _this.queryForm.pageSize_ = res.data.pageSize_
                    _this.queryForm.total_ = res.data.total_
                    _this.queryForm.pageNum_ = res.data.pageNum_
                })
            })
        },
        handleSelectionChange(val) {
            this.multipleSelection.ids = []
            val.forEach(menu => {
                this.multipleSelection.ids.push(menu.id)
            })
        },
        handleSizeChange(val) {
            this.queryForm.pageSize_ = val
            this.getListData()
        },
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val
            this.getListData()
        }
    }
}
</script>
<style lang="scss" scoped>
.condition-title {
    color: #2b3b4e;
    font-size: 18px;
    line-height: 24px;
    font-weight: bold;
}
.sub-title {
    margin: 16px 0 65px 0;
    font-size: 16px;
    color: #000020;
    letter-spacing: 0;
}
</style>
